import wechatOa from "@/utils/wechat"

export function goPay (options: any) {
    return new Promise( async (resove:any, reject:any) => {
        // @ts-ignore
        // #ifdef MP-WEIXIN
        await uni.requestPayment({
            provider: "wxpay",
            ...options,
            success(res:any) {
                resove(res)
            },
            fail(err:any) {
                if (err.errMsg == 'requestPayment:fail cancel') {
                    uni.showToast({
                        title: '您取消了支付',
                        icon: 'none'
                    })
                }
                reject(err)
            }
        })
        // #endif

        // #ifdef H5
        const h5PayBack = await wechatOa.pay({
            ...options,
        })
        console.log('h5PayBack======>',h5PayBack)
        resove(h5PayBack)
        // #endif
    })
}

